<?php
 require('SimpleImage.php');
$uploaddir = '../../images-products/'; 
$name = basename($_FILES['uploadfile']['name']);
$type = $_FILES['uploadfile']['type'];
if(($type =='image/bmp' || $type == 'image/jpeg' || $type =='image/gif'|| $type =='image/pjpeg' || $type =='image/png' || $type =='image/jpg' ))
 {
	$now = getdate();
    $currentTime = $now["hours"] . $now["minutes"] . $now["seconds"];
    $currentDate = $now["year"] . $now["mon"] . $now["mday"];
	$time = $currentDate . $currentTime;
	$photo = strstr($name,".");
    $pic = $time.$photo;
	$file = $uploaddir . $pic; 
     move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file);
     $image = new SimpleImage();
     $image->load("../../images-products/" . $pic);
     $image->resizeToWidth(100);
     $image->save("../../images-products/thumbnail/" . $pic);
	// header('Content-type: application/json');
    echo $pic;
 }
 else {
	echo "error";
 }
?>